/**
 * 
 */
package com.geezdata.cps.ttk.core;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;

import com.geezdata.cps.cqrs.command.bus.CommandBus;
import com.geezdata.cps.cqrs.command.bus.impl.DefaultCommandBus;
import com.geezdata.cps.cqrs.event.bus.EventBus;
import com.geezdata.cps.cqrs.event.bus.impl.DefaultEventBus;
import com.geezdata.cps.cqrs.event.listener.container.ListenerContainer;
import com.geezdata.cps.cqrs.event.publish.impl.DefaultAsyncPublisher;
import com.geezdata.cps.cqrs.event.publish.impl.DefaultPublisher;
import com.geezdata.cps.ttk.integration.TtkIntegrationApplicationContext;
import com.geezdata.cps.ttk.mapper.TtkMapperApplicationContext;

/**
 * @author sszheng
 * @date 创建时间：2018年3月26日 下午5:06:44
 *
 */
@SpringBootApplication
@Import(value = {
		TtkMapperApplicationContext.class,
		TtkIntegrationApplicationContext.class
})
@PropertySource(value = {
        "classpath:ttk-core-env.properties",
        "classpath:ttk-core-base.properties"
})
public class TtkCoreApplicationContext {
	@Bean
	public CommandBus commandBus() {
		return new DefaultCommandBus();
	}
	
	@Bean
    public EventBus eventBus() {
        EventBus eventBus = new DefaultEventBus();
        eventBus.register(defaultPublisher());
        eventBus.register(asyncPublisher());
        return eventBus;
    }
	
	@Bean
    public DefaultPublisher defaultPublisher() {
        return new DefaultPublisher(listenerContainer());
    }
	
    @Bean(destroyMethod = "stop" )
    public DefaultAsyncPublisher asyncPublisher() {
        return new DefaultAsyncPublisher(listenerContainer());
    }
    
    @Bean
    public ListenerContainer listenerContainer() {
        return new ListenerContainer();
    }
}
